(function() {
    Nokia.TextLink = Nokia.Widget.extend({
        initialize: function(options) {
            var instance = this;

			var defaults = {
				url: false,
				label: ''
            };

            instance.options = jQuery.extend(defaults, options);

            instance.element = jQuery( instance.options.element );

            instance._super.apply(instance, [instance.options]);

            instance.registerData("link");

            instance._attachEvents();
            instance._create();

			instance.registerVibrationOn([]);
			instance.fireCallback('create');
        },

		go: function(url) {
			var instance = this;
			var options = instance.options;
			var element = instance.element;
			var url = url || options.url;
			var Styles = instance.Styles;

			Nokia.util.addClass(element[0], Styles.linkVisited);
			instance.openURL(url);
		},

		_attachEvents: function() {
			var instance = this;
			var options = instance.options;
			var url = options.url;
			var element = instance.element;

			var linkAction = function(e) {

				if (options.url) {
					instance.go();
				}

				instance.fireCallback('click', [e, url]);

				return false;
			};

			element.bind('click.textlink', linkAction);
			Nokia.util.bindEnter(element, linkAction);
		},

		_create: function() {
			var instance = this;
			var element = instance.element;
			var options = instance.options;
			var label = options.label;
			var url = options.url;
			var Styles = instance.Styles;

			if ( label ) {
				element.html( label );
			}

			Nokia.util.addClass(element[0], Styles.link);

			element.attr('href', 'javascript:void(0);');

			if (options.style) {
				instance.element.css(options.style);
			}
		},

		Styles: {
			link: 'nokia-link',
			linkVisited: 'nokia-link-visited'
		}
    });
})();